package com.atguigu;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Random;

/**
 * 秒杀案例
 *
 * @author 墨苍璃
 */
public class SecKillServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public SecKillServlet() {
        super();
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String userid = new Random().nextInt(50000) + "";
        String prodid = request.getParameter("prodid");

        //        boolean isSuccess = SecKillRedis.doSecKill(userid, prodid);
        boolean isSuccess = SecKillRedisByScript.doSecKill(userid, prodid);

        response.getWriter().print(isSuccess);
    }

}
